com.cete.dynamicpdf
Class Document



Examples Description
Example 1 This example shows how to use the document in the creation of a simple PDF document.
Example 2 This example shows how to output the PDF to a byte array.
Example 3 This example shows how to output the PDF to a file.
Example 4 This example shows how to output the document to a memory stream object.
Example 5 This example shows how to output the document to the current web page and to a pdf file.
Example 6 This example shows how to output the document to the current web page and shows dialog box whether to save or not.
Example 7 This example shows how to output the document to the current web page and specifies whether browser to cache or not.
Example 8 This example shows how to output the document to the current web page.
Example 9 This example shows how to create an Xmp Metadata and Add it to the document.
Example 10 This example shows simple HTML being displayed on the page.
Example 11 This example shows simple HTML being displayed on the page.
Example 12 This example shows simple HTML being displayed on the page.
Example 13 This example shows simple HTML being displayed on the page.
Example 14 This example shows simple HTML being displayed on the page.
Example 15 This example shows simple HTML being displayed on the page.


Example 1 : This example shows how to use the document in the creation of a simple PDF document.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;

  public class MyClass {
    public static void Main(String args[]) {

          // Create a PDF Document
          Document document = new Document();

          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add(page);

          // Add a label to the page
          page.getElements().add(new Label("My PDF Document", 0,
          0, 512, 40, Font.getHelvetica(), 30, TextAlign.CENTER));

          // Save the PDF document
         document.draw("[PhysicalPath]/MyDocument.pdf");
    }
  } 

Top

EXample 2 : This example shows how to output the PDF to a byte array.
    
    import com.cete.dynamicpdf.*;
    import com.cete.dynamicpdf.pageelements.Label;

    public class MyClass {
      public static void Main(String args[]) {

          // Create a PDF Document
          Document document = new Document();

          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add(page);

          // Add a label to the page 
	  Page.getElements().add( new Label( "My PDF Document", 0, 0, 512, 40, Font.getHelvetica(), 30, TextAlign.CENTER ) );

        // Save the PDF document to a byte array
        byte[] pdfData = document.draw();
    }
  } 

Top

Example 3 : This example shows how to output the PDF to a file.
  
  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;

  public class MyClass {
    public static void Main(String args[]) {

          // Create a PDF Document
          Document document = new Document();

          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add(page);

          // Add a label to the page 
          Page.getElements().add( new Label( "My PDF Document", 0, 0, 512, 40, Font.getHelvetica(), 30, TextAlign.CENTER ) );
  
          // Save the PDF document
         document.draw("[Physicalpath]\MyDocument.pdf");
    }
}

Top

Example 4 : This example shows how to output the document to a memory stream object.
 
  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;

  public class MyClass {
    public static void Main(String args[]) {

          // Create a PDF Document
          Document document = new Document();

          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add(page);

          // Add a label to the page 
          Page.getElements().add( new Label( "My PDF Document", 0, 0, 512, 40, Font.getHelvetica(), 30, TextAlign.CENTER ) );
 
	  // Create a memory stream object to save to
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        
          // Output the PDF to the MemoryStream
          document.draw(outputStream);
    }
  }

Top

Example 5 : This Example shows to Output the document to current web page and to a pdf file.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;
  import java.io.IOException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  public class HelloWorld  extends HttpServlet {
    
    ServletOutputStream sOut;
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException,ServletException {
               
        sOut = res.getOutputStream();
        // Create a document and set it's properties
        Document objDocument = new Document();
        objDocument.setCreator("HelloWorld.java");
        objDocument.setAuthor("Your Name");
        objDocument.setTitle("Hello World");
        
        // Create a page to add to the document
        Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT,54.0f);
               
        // Create a Label to add to the page
        String strText = "Hello World...\nFrom DynamicPDF Generator " +
                         "for Java\nDynamicPDF.com";
        Label objLabel = new Label(strText, 0, 0, 504, 100, Font.getHelvetica(),
                                 18, TextAlign.CENTER);
        
        // Add label to page
        objPage.getElements().add(objLabel);
        
        // Add page to document
        objDocument.getPages().add(objPage);
        
        // Outputs the document to current web page.
        objDocument.drawToWeb(req, res , sOut, "[physicalpath]/HelloWorld.pdf");
        sOut.close();
    }
  }

Top

Example 6 : This Example shows to Output the document to current web page and shows dialog box whether to save or not.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;
  import java.io.IOException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  public class HelloWorld  extends HttpServlet {
    
    ServletOutputStream sOut;
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException,ServletException {
               
        sOut = res.getOutputStream();
        // Create a document and set it's properties
        Document objDocument = new Document();
        objDocument.setCreator("HelloWorld.java");
        objDocument.setAuthor("Your Name");
        objDocument.setTitle("Hello World");
        
        // Create a page to add to the document
        Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT,54.0f);
               
        // Create a Label to add to the page
        String strText = "Hello World...\nFrom DynamicPDF Generator " +
                         "for Java\nDynamicPDF.com";
        Label objLabel = new Label(strText, 0, 0, 504, 100, Font.getHelvetica(),
                                 18, TextAlign.CENTER);
        
        // Add label to page
        objPage.getElements().add(objLabel);
        
        // Add page to document
        objDocument.getPages().add(objPage);
        
        // Outputs the document to current web page.
        objDocument.drawToWeb(req, res , sOut, "[physicalpath]/HelloWorld.pdf",true);
        sOut.close();
    }
  }

Top

Example 7 : This Example shows to Output the document to current web page and specificies whether browser has to cache or not.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;
  import java.io.IOException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  public class HelloWorld  extends HttpServlet {
    
    ServletOutputStream sOut;
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException,ServletException {
               
        sOut = res.getOutputStream();
        // Create a document and set it's properties
        Document objDocument = new Document();
        objDocument.setCreator("HelloWorld.java");
        objDocument.setAuthor("Your Name");
        objDocument.setTitle("Hello World");
        
        // Create a page to add to the document
        Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT,54.0f);
               
        // Create a Label to add to the page
        String strText = "Hello World...\nFrom DynamicPDF Generator " +
                         "for Java\nDynamicPDF.com";
        Label objLabel = new Label(strText, 0, 0, 504, 100, Font.getHelvetica(),
                                 18, TextAlign.CENTER);
        
        // Add label to page
        objPage.getElements().add(objLabel);
        
        // Add page to document
        objDocument.getPages().add(objPage);
        
        // Outputs the document to current web page.
        objDocument.drawToWeb(req, res , sOut,true);
        sOut.close();
    }
  }

Top

Example 8 : This Example shows to Output the document to current web page.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;
  import java.io.IOException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  public class HelloWorld  extends HttpServlet {
    
    ServletOutputStream sOut;
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException,ServletException {
               
        sOut = res.getOutputStream();
        // Create a document and set it's properties
        Document objDocument = new Document();
        objDocument.setCreator("HelloWorld.java");
        objDocument.setAuthor("Your Name");
        objDocument.setTitle("Hello World");
        
        // Create a page to add to the document
        Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT,54.0f);
               
        // Create a Label to add to the page
        String strText = "Hello World...\nFrom DynamicPDF Generator " +
                         "for Java\nDynamicPDF.com";
        Label objLabel = new Label(strText, 0, 0, 504, 100, Font.getHelvetica(),
                                 18, TextAlign.CENTER);
        
        // Add label to page
        objPage.getElements().add(objLabel);
        
        // Add page to document
        objDocument.getPages().add(objPage);
        
        // Outputs the document to current web page.
        objDocument.drawToWeb(req, res , sOut);
        sOut.close();
    }
  }

Top

Example 9 : This example shows how to create an Xmp Metadata and Add it to the document.
import com.cete.dynamicpdf.*; public class MyClass { public static void Main(String args[]) { // Create a PDF Document Document document = new Document(); // Add blank pages to the document document.getPages().add( new Page( PageSize.LETTER ) ); document.getPages().add( new Page( PageSize.LETTER ) ); // Create an Xmp Metadata XmpMetadata xmp = new XmpMetadata(); // Add the Xmp Metadata to the document document.setXmpMetadata( xmp ); // Save the PDF document document.draw("[PhysicalPath]/MyDocument.pdf"); } } }

Top

Example 10 : This example shows simple HTML being displayed on the page.

   import com.cete.dynamicpdf.*;
   import com.cete.dynamicpdf.pageelements.html.*;
 
   public class MyClass {
     public static void main(String args[]) {
         // Create a PageDimensions
         PageDimensions dimensions = new PageDimensions(PageSize.LETTER, PageOrientation.PORTRAIT, 50.0f);

         // Create a HtmlAreaPadding
         HtmlAreaPadding padding = new HtmlAreaPadding(20.0f, 0.0f, 20.0f, 0.0f);

         // Create a file path
         String filePath = "[physicalpath]/TestPage.html";

         // Create a PDF Document
         Document document = Document.fromHtml(filePath, dimensions, padding);
 
         // Save the PDF
         document.draw("[Physicalpath]/MyDocument.pdf" );
      }
    }

Top

Example 11 : This example shows simple HTML being displayed on the page.

   import com.cete.dynamicpdf.*;
   import com.cete.dynamicpdf.pageelements.html.*;
   import java.net.URI;
   import java.net.URISyntaxException;
 
   public class MyClass {
     public static void main(String args[]) {
         // Create a PageDimensions
         PageDimensions dimensions = new PageDimensions(PageSize.LETTER, PageOrientation.PORTRAIT, 50.0f);

         // Create a baseHref
         URI baseHref = null;
         try {
             baseHref = new URI("[physicalpath]");
         } catch (URISyntaxException ex) {
             System.out.println("A URISyntaxException was caught :"+ ex.getMessage());
         }		

         // Create a file path
         String filePath = "[physicalpath]/TestPage.html";

         // Create a PDF Document
         Document document = Document.fromHtml(filePath, dimensions, baseHref);
 
         // Save the PDF
         document.draw("[Physicalpath]/MyDocument.pdf" );
      }
    }

Top

Example 12 : This example shows simple HTML being displayed on the page.

   import com.cete.dynamicpdf.*;
   import com.cete.dynamicpdf.pageelements.html.*;
   import java.net.URI;
   import java.net.URISyntaxException;
 
   public class MyClass {
     public static void main(String args[]) {
         // Create a PageDimensions
         PageDimensions dimensions = new PageDimensions(PageSize.LETTER, PageOrientation.PORTRAIT, 50.0f);

         // Create a baseHref
         URI baseHref = null;
         try {
             baseHref = new URI("[physicalpath]");
         } catch (URISyntaxException ex) {
             System.out.println("A URISyntaxException was caught :"+ ex.getMessage());
         }		

         // Create a HtmlAreaPadding
         HtmlAreaPadding padding = new HtmlAreaPadding(20.0f, 0.0f, 20.0f, 0.0f);

         // Create a file path
         String filePath = "[physicalpath]/TestPage.html";

         // Create a PDF Document
         Document document = Document.fromHtml(filePath, dimensions, padding, baseHref);
 
         // Save the PDF
         document.draw("[Physicalpath]/MyDocument.pdf" );
      }
    }

Top

Example 13 : This example shows simple HTML being displayed on the page.

   import com.cete.dynamicpdf.*;
   import com.cete.dynamicpdf.pageelements.html.*;
   import java.net.URI;
   import java.net.URISyntaxException;
 
   public class MyClass {
     public static void main(String args[]) {
         // Create a PageDimensions
         PageDimensions dimensions = new PageDimensions(PageSize.LETTER, PageOrientation.PORTRAIT, 50.0f);

         // Create a uri
         URI uri = null;
         try {
             uri = new URI("[physicalpath]/SimpleHtml.html");
         } catch (URISyntaxException ex) {
             System.out.println("A URISyntaxException was caught :"+ ex.getMessage());
         }		

         // Create a HtmlAreaPadding
         HtmlAreaPadding padding = new HtmlAreaPadding(20.0f, 0.0f, 20.0f, 0.0f);

         // Create a PDF Document
         Document document = Document.fromHtml(uri, dimensions, padding);
 
         // Save the PDF
         document.draw("[Physicalpath]/MyDocument.pdf" );
      }
    }

Top

Example 14 : This example shows simple HTML being displayed on the page.

   import com.cete.dynamicpdf.*;
   import com.cete.dynamicpdf.pageelements.html.*;
   import java.net.URI;
   import java.net.URISyntaxException;
 
   public class MyClass {
     public static void main(String args[]) {
         // Create a PageDimensions
         PageDimensions dimensions = new PageDimensions(PageSize.LETTER, PageOrientation.PORTRAIT, 50.0f);

         //Create a Uri
         URI uri =  null;
         try {
             uri = new URI("[physicalpath]/SimpleHtml.html");
         } catch (URISyntaxException ex) {
             System.out.println("A URISyntaxException was caught :"+ ex.getMessage());
         }

         // Create a baseHref
         URI baseHref = null;
         try {
             baseHref = new URI("[physicalpath]");
         } catch (URISyntaxException ex) {
             System.out.println("A URISyntaxException was caught :"+ ex.getMessage());
         }		

         // Create a PDF Document
         Document document = Document.fromHtml(uri, dimensions, baseHref);
 
         // Save the PDF
         document.draw("[Physicalpath]/MyDocument.pdf" );
      }
    }

Top

Example 15 : This example shows simple HTML being displayed on the page.

   import com.cete.dynamicpdf.*;
   import com.cete.dynamicpdf.pageelements.html.*;
   import java.net.URI;
   import java.net.URISyntaxException;
 
   public class MyClass {
     public static void main(String args[]) {
         // Create a PageDimensions
         PageDimensions dimensions = new PageDimensions(PageSize.LETTER, PageOrientation.PORTRAIT, 50.0f);

         // Create a Uri
         URI uri = null;
         try {
             uri = new URI("[physicalpath]/SimpleHtml.html");
         } catch (URISyntaxException ex) {
             System.out.println("A URISyntaxException was caught :"+ ex.getMessage());
         }		

         // Create a HtmlAreaPadding
         HtmlAreaPadding padding = new HtmlAreaPadding(20.0f, 0.0f, 20.0f, 0.0f);

         // Create a baseHref
         URI baseHref = null;
         try {
             baseHref = new URI("[physicalpath]");
         } catch (URISyntaxException ex) {
             System.out.println("A URISyntaxException was caught :"+ ex.getMessage());
         }		

         // Create a PDF Document
         Document document = Document.fromHtml(uri, dimensions, padding, baseHref);
 
         // Save the PDF
         document.draw("[Physicalpath]/MyDocument.pdf" );
      }
    }

Top